//
//  DDInputAccessoryPickerView.m
//  DDPickerKeyboardView
//
//  Created by zhipeng on 16/11/10.
//  Copyright © 2016年 lqd. All rights reserved.
//

#import "DDInputAccessoryPickerView.h"
@interface DDInputAccessoryPickerView ()
@property (copy , nonatomic) NullBlock leftBlock ;
@property (copy , nonatomic) NullBlock rightBlock;
@end
@implementation DDInputAccessoryPickerView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
       self.backgroundColor = [UIColor colorWithRed:247 / 255.0 green:247 / 255.0 blue:248 / 255.0 alpha:1];
        [self addSubview:self.titleLabel ];
        [self addSubview:self.leftButton ];
        [self addSubview:self.rightButton];
    }
    return self;
}


#pragma mark ----- 懒加载 -----
- (UILabel *)titleLabel
{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width - 150, 30)];
        _titleLabel.text = @"选择收货时间";
        _titleLabel.textColor = [UIColor grayColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.center = CGPointMake([UIScreen mainScreen].bounds.size.width / 2.0, self.frame.size.height / 2.0);
    }
    return _titleLabel;
}
- (UIButton *)leftButton
{
    if (!_leftButton) {
        _leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
        _leftButton.center = CGPointMake(_leftButton.frame.size.width / 2.0 + 10, self.frame.size.height / 2.0);
        _leftButton.titleLabel.textColor = [UIColor blackColor];
        _leftButton.backgroundColor = [UIColor lightGrayColor];
        _leftButton.alpha = 0.9;
        _leftButton.layer.cornerRadius = 8;
        [_leftButton setTitle:@"取消" forState:(UIControlStateNormal)];
        [_leftButton addTarget:self action:@selector(leftButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _leftButton;
}
- (UIButton *)rightButton
{
    if (!_rightButton) {
        _rightButton  = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 30)];
        _rightButton.center = CGPointMake([UIScreen mainScreen].bounds.size.width - _rightButton.frame.size.width / 2.0 - 10, self.frame.size.height / 2.0);
        _rightButton.alpha = 0.9;
        _rightButton.titleLabel.textColor = [UIColor blackColor];
        _rightButton.layer.cornerRadius = 8;
        _rightButton.backgroundColor = [UIColor lightGrayColor];
        [_rightButton setTitle:@"确定" forState:(UIControlStateNormal)];
        [_rightButton addTarget:self action:@selector(rightButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _rightButton;
}
#pragma mark ----- 事件处理 -----
- (void)rightButtonAction : (UIButton *)button
{
    if (self.leftBlock) {
        self.leftBlock();
    }
}
- (void)leftButtonAction : (UIButton *)button
{
    if (self.rightBlock) {
        self.rightBlock();
    }
}
- (void)editStyle : (StyleBlock)block
{
    if (block) {
        block(self.titleLabel,self.leftButton,self.rightButton);
    }
}
/**
 *  左边按钮调用的Block
 */
- (void)leftBlock  : (NullBlock )block
{
    self.leftBlock  = block;
}
/**
 *  右边按钮调用的Block
 */
- (void)rightBlock : (NullBlock )block
{
    self.rightBlock = block;
}
@end
